<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ page isELIgnored="false" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html>
<head>
   <link href="<s:url value="/resources"/>/css/style_new.css" rel="stylesheet" type="text/css" />
    <link href="<s:url value="/resources"/>/css/main_new.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/ajaxfileupload.js"></script>
<style>
html,body {
	margin: 0;
	padding: 0;
	font-size: 85%;
}
</style>
<script >
  $(function(){
      //日期控件处理
    $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#datepicker2" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $("#file").button();
    $("#shangc").button();
    loadTab();   
 });
 
  function loadTab(){
    //加载列表
    $("#myTab").jqGrid({      
		    url:'<s:url value="/hwjs"/>/findFaydwenjGrid',   
		    datatype: 'json',
		    mtype: 'post',         
		   	colNames:['编辑','上传时间','文件名','记录数'],
		   	colModel:[
		      	{name:'caoz',index:'wenjid',width:60,align:"center"}, 
		   		{name:'caosj',index:'caosj',width:120},
		   		{name:'wenjm',index:'wenjm'},
		   		{name:'jilts',index:'jilts'},		
		   	],
		    jsonReader: {
		           repeatitems : false, 
		           id: 'wenjid'
		         },   
		    height:250, 
		    width: 1070, 	
		   	rowNum:10,
		   	rowList:[10,30,50],     	
		   	pager: '#pager', 
		   	rownumbers: true,   	 
		    viewrecords: true,
		    multiselect : true,
		    sortorder: 'desc', 
		    caption: "发运单批量导入",
			gridComplete:function()
				{ //在此事件中循环为每一行添编辑链接 	
					var ids=$("#myTab").jqGrid('getDataIDs'); 
					for(var j=0; j<ids.length; j++)
					{		
					     id=ids[j];		    
						 caoz="<a href='#' style='color:#f60' onclick='edit("+ id +")'>编辑</a>&nbsp;";
						 $("#myTab").jqGrid('setRowData',id, { caoz: caoz }); 
					}
				}	
		  });  		
    }
         
   //查询
	function search(){   
	  var formdata = $("#form1").serialize();  
	  $("#myTab").jqGrid('setGridParam',{url:'findFaydwenjGrid?'+formdata,mtype:'post',page:1}).trigger("reloadGrid"); 
	}
	
	//重置
	function resetSearch()
    {
		$('#list_search  input[type=text]').val('');
		$('#list_search select').val('-1');
	}
	
	//批量上传发运单
	function importfyd()
	{
	   $.ajaxFileUpload({
		        url: "<s:url value="/hwjs"/>/importfyd",
		        fileElementId: "file",
		        secureuri :false,
		        dataType: "text",
		        success : function (data, status){ 
		        	 //alert(data.toLowerCase()); 
		         if (data.toLowerCase()=="<pre>文件上传成功!</pre>"){
		        	alert("文件上传成功!"); 
		        	$("#myTab").trigger("reloadGrid"); 
		         }else{
		        	 alert("文件上传失败，请检查上传文件！");  
		         }}, 
		        error: function (data, status, e){ 
		        alert(data);  
		        }         
      }); 
	}
	
	
	//批量删除
		function batchremove() {	
			var sysid = $("#myTab").jqGrid('getGridParam','selarrrow');
			if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			}
			else
			{
			var url = "<s:url value="/hwjs"/>/removeFydBatch?sysid="+sysid;
			$( "#dialog-confirm" ).dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						"确认": function() {
							$.post(url, function(data) {
								var obj = eval('(' + data + ')');
								if(obj.success==true){
								        location.href ="<s:url value="/hwjs"/>/directFyddb";
								        //loadTab();
								        /*  $("#myTab").jqGrid('setGridParam',{   
						                          url:'<s:url value="/hwjs"/>//directFyddb',
												  mtype:'post',
												  page:1
							              }).trigger("reloadGrid");   */
								 }else{
								         alert(obj.msg);
								       }
		                   });
		                   $( this ).dialog( "close" ); 
						},
						"返回": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			}
		}
 
   //单击编辑链接的操作 
   function edit(id) { 
       openwindow('<s:url value="/hwjs"/>/editFydTemp?wenjid='+ id);
    }
    
   //打开界面
   function openwindow(url){
	    var sheight = screen.height-70;
	    var swidth = screen.width-10;
	    var winoption ="dialogHeight:"+sheight+"px;dialogWidth:"+ swidth +"px;status:yes;scroll:yes;resizable:yes;center:yes";
	    var result=window.showModalDialog(url,window,winoption); 
	}
	  
  
	//下载
	function xiaz(){   
		var url = encodeURI('<%=path %>/download/fayundan.xls','utf-8');
		window.location.href = url;
	}
	</script>

</head>

<body>
	<div class="container">
	 <div class="containerbox">
	  <div class="btn-bar"> 
	    <a  href="#" class="btn" onclick= "xiaz();"><img src="<s:url value="/resources"/>/img/ico_23.gif" /><span>下载模版</span></a> 
	    <a  href="#" class="btn" onclick=""><img src="<s:url value="/resources"/>/img/ico_25.gif" /><span>删除</span></a>
	    <input type="file" id="file" name="file"  style="height:30px;width:280px">
	    <input id="shangc" type="button" value="上传文件" onclick="importfyd();" />
	   </div>
	 <div class="search mt10" id="list_search">
	<form id="form1" method="post">
	<table  class="search-table"  style="width:90%"  cellpadding="0" cellspacing="0" border="0"> 
		<tr>
			<td>上传日期:</td>
			<td>
				<input id="datepicker1" type="text" class="form-textbox" style="width: 93px;" name="aa" /> -
				<input id="datepicker2" type="text" class="form-textbox" style="width: 93px;" name="bb" />
			</td>
			<td colspan="6">&nbsp;</td>
		</tr>
		<tr>
           <td align="left" colspan="8">
                  <input name="" type="button" class="form-button-query form-button" value="查询" onclick="search();"/>
                  <input name="" type="button" class="form-button-reset form-button" value="重置"  onclick="resetSearch();"/>
            </td>
        </tr>
     </table>
	 </form>
    </div>
    	   <table id="myTab" class="scroll" cellpadding="0" cellspacing="0"></table>  
		   <div id="pager" class="scroll"></div>  
		   <div id="message" class="scroll"></div>
		 </div>
		 </div> 
		<div id="dialog-confirm" title="是否确认？"></div>
</body>
</html>
